require 'capistrano/ext/multistage'

set :application, "benchmark"
set :repository,  "http://svn.crap4j.org/crap4j/benchmark"

# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/home/crap4j/#{application}_staging"

set :use_sudo, false
set :deploy_via, :export 
set :user, "crap4j"


set (:password) { Capistrano::CLI.password_prompt("Login password: ") } 
set (:scm_password) { Capistrano::CLI.password_prompt("Subversion password: ") } 
# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion

role :app, "crap4j.org"
role :web, "crap4j.org"
role :db,  "crap4j.org", :primary => true

after :update, :after_update

namespace :deploy do
desc "Restart the web server fake"
  task :restart, :roles => :app do
    #sudo "apachectl graceful"
    run "#{current_release}/script/process/reaper --dispatcher=dispatch.fcgi"
  end
end
  
desc <<DESC
clean up the symlink. the default will make it to current, we want it to be current/public
Using the default caused an infinite Rewrite recursion from apache on Dreamhost
DESC
task :after_symlink, :roles => :app do
  on_rollback { run "rm -f #{current_path}; ln -s #{previous_release}/public #{current_path}; true" }
  run "rm #{current_path}"
  run "ln -nfs #{current_release}/public #{current_path}"
end

set :crap4j_version, "1.1.6"
task :put_crap4j, :roles => :app do
  #"scp org.crap4j/build/crap4j_ant_cli.jar crap4j@crap4j.org:/home/crap4j/builds/crap4j_ant_#{crap4j_version}.jar"
  #"scp org.crap4j.eclipse.updatesite/build/org.crap4j.eclipse.updatesite_#{crap4j_version}.zip  crap4j@crap4j.org:/home/crap4j/builds/"
  
  # not working old cleanup
  #     rm #{static_site}/downloads/*.jar #{static_site}/downloads/*.zip &&
  run  <<-CMD
    cp /home/crap4j/builds/crap4j_ant_#{crap4j_version}.jar #{static_site}/downloads/ &&
    ln -nfs #{static_site}/downloads/crap4j_ant_#{crap4j_version}.jar #{static_site}/downloads/crap4j_ant_latest.jar &&
    cp /home/crap4j/builds/org.crap4j.eclipse.updatesite_#{crap4j_version}.zip #{static_site}/downloads/ &&
    ln -nfs #{static_site}/downloads/org.crap4j.eclipse.updatesite_#{crap4j_version}.zip #{static_site}/downloads/latest.zip &&
    rm -rf #{static_site}/downloads/update/site.xml #{static_site}/downloads/update/features #{static_site}/downloads/update/plugins &&
    cd #{static_site}/downloads &&
    jar xf #{static_site}/downloads/org.crap4j.eclipse.updatesite_#{crap4j_version}.zip
  CMD
end
